<?php

declare (strict_types = 1);

namespace app\admin\controller\notification;

use think\Request;
use sheep\controller\Backend;
use sheep\exception\SheepException;
use app\admin\model\notification\Notification as NotificationModel;
use sheep\facade\Uploader;

class Notification extends Backend
{

    protected function initialize()
    {
        $this->model = new NotificationModel;
    }

    public function notificationType()
    {
        $admin = $this->auth()->user();

        $notificationType = NotificationModel::$notificationType;

        $newType = [];
        foreach ($notificationType as $type => $name) {
            $newType[] = [
                'label' => $name,
                'value' => $type,
                'unread_num' => $admin->unreadNotifications()->notificationType($type)->count()
            ];
        }

        $result = [
            'unread_num' => array_sum(array_column($newType, 'unread_num')),
            'notification_type' => $newType
        ];

        return success('消息类型', $result);
    }
}